package elementui.form;

/**
 * javazgw@gmail.com windown 10
 * 2020/6/28 23:02
 */
public class Upload extends FormItem{

    String action;
    String headers;
    boolean multiple;

    String name;
    boolean show_file_list;
    String accept;  //接受上传的文件类型（thumbnail-mode 模式下此参数无效）	string
    String list_type;//文件列表的类型	string	text/picture/picture-card	text
    boolean auto_upload	;//是否在选取文件后立即进行上传	boolean	—	true
    String file_list;//上传的文件列表, 例如: [{name: 'food.jpg', url: 'https://xxx.cdn.com/xxx.jpg'}]	array	—

    int limit;//	最大允许上传个数	number
    @Override
    String getDefaultHmtl() {
        return "<el-upload\n" +
                "  class=\"upload-demo\"\n" +
                "  action=\""+getAction()+"\"\n" +
                "  :on-preview=\"handlePreview\"\n" +
                "  :on-remove=\"handleRemove\"\n" +
                "  :before-remove=\"beforeRemove\"\n" +
                "  multiple\n" +
                "  :limit=\"3\"\n" +
                "  :on-exceed=\"handleExceed\"\n" +
                "  :file-list=\""+getVmode()+"\">\n" +
                "  <el-button size=\"small\" type=\"primary\">点击上传</el-button>\n" +
                "  <div slot=\"tip\" class=\"el-upload__tip\">只能上传jpg/png文件，且不超过500kb</div>\n" +
                "</el-upload>";
    }

    @Override
    String getDefaultScript() {
        return "handleRemove(file, fileList) {\n" +
                "        console.log(file, fileList);\n" +
                "      },\n" +
                "      handlePreview(file) {\n" +
                "        console.log(file);\n" +
                "      },\n" +
                "      handleExceed(files, fileList) {\n" +
                "        this.$message.warning(`当前限制选择 3 个文件，本次选择了 ${files.length} 个文件，共选择了 ${files.length + fileList.length} 个文件`);\n" +
                "      },\n" +
                "      beforeRemove(file, fileList) {\n" +
                "        return this.$confirm(`确定移除 ${ file.name }？`);\n" +
                "      }";
    }

    @Override
    String getData() {
//        return data+" : [{name: 'food.jpeg', url: 'https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100'}, {name: 'food2.jpeg', url: 'https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100'}]";


        if(this.data == null )
        {
            return getVmode()+": []";
        }
        return data;
    }

    public void setAction(String action)
    {
        this.action = action;
    }

    public String getAction()
    {
        return this.action;
    }
}
